<script type="text/javascript">
var paginationTotal = 1;//记录总数
$(function () {
//	initData(0);
   	clear();
   	
   	$('#dateFrom,#dateTo').datepicker({
		changeMonth: true,
		changeYear: true,			 
		dateFormat: 'yy-mm-dd'
	});
   	
    $("#add").dialog({
   		autoOpen:false,
        modal:true,
        width:380,
        height:450,
        show:"slide",
        buttons:{
        	'<{$lang.ok}>':function () {save();},
            '<{$lang.cancel}>':function () {
                    $(this).dialog('close');
                }
            }
	});
	
	$(".toEnter").keyup(function(e){
		var key = e.which;
		if(key==13){
			initData(0);
		}
	});
	
});

    function loadData(page, pageSize) {
        var cbh_refer_id = $('[name=cbh_refer_id]').val();
        var customer_id = $('[name=customer_id]').val();
        var cbh_op_type = $('[name=cbh_op_type]').val();
        var dateFrom = $('[name=dateFrom]').val();
        var dateTo = $('[name=dateTo]').val();

        $.ajax({
            type:"POST",
            async:false,
            dataType:"json",
            url:"/customer/balance-history/list", //请求的处理url
            data:{
                'page':page, 'pageSize':pageSize,
                'cbh_refer_id':cbh_refer_id, 'customer_id':customer_id,
                'cbh_op_type':cbh_op_type, 'dateFrom':dateFrom,
                'dateTo':dateTo
            },

            success:function (json) {
                var list = "";
                paginationTotal = json.total;
                if (json.ask != 1) {
                    list = "<td colspan='12' class=''>&nbsp;<{$lang.no_data}></td>";
                } else {
                    var i = paginationCurrentPage == 1 ? 1 : paginationPageSize * (paginationCurrentPage - 1) + 1;
					var j = page == 1 ? 1 : pageSize * (page - 1) + 1;
                    $.each(json.result, function (key, val) {
                        if ((key + 1) % 2 == 1) {
                            list += "<tr class=''>";
                        } else {
                            list += "<tr class='even-tr'>";
                        }
						list += "<td >" + (j++) + "</td>";
                        list += "<td >" + val.customer_id + "</td>";
                        list += "<td >" + val.cbh_add_time + "</td>";
                        list += "<td >" + val.cbh_type + "</td>";
                        list += "<td >" + val.cbh_base_value + "</td>";
                        list += "<td >" + val.cbh_op_type + "</td>";
                        list += "<td >" + val.cbh_current_value + "</td>";
                        list += "<td >" + val.cbh_class + "</td>";
                        list += "<td >" + val.cbh_note + "</td>";
                        list += "<td >" + val.cbh_refer_id + "</td>";
                        list += "</tr>";
                    });
                }
                $("#list").html(list);
            }
        });
    }

    function search() {
        initData(0);
    }

    function clear() {
        $('[name=cbh_refer_id]').val('');
        $('[name=customer_id]').val('');
        $('[name=cbh_op_type]').val('');
        $('[name=dateFrom]').val('');
        $('[name=dateTo]').val('');
    }

</script>
<style type="text/css">
    #iTitle div {
        display: inline-block;
        float: left;
        padding: 0 0 0 10px;
        margin-bottom: 12px;
    }

    .mySelect {
        height: 22px;
        border: 1px solid #CCCCCC;
    }

    #iTitle input {
        height: 20px;
        border: 1px solid #CCCCCC;
    }
</style>

<div class="search_div">
    <div id="iTitle">
        <form id="seach-form" onsubmit="return false;" action="" method="post" name="seach-form">
            <div style="padding-left:10px"><{$lang.referNo}>:</div>
            <div>
                <input id="cbh_refer_id" class="toEnter" type="text" value="" name="cbh_refer_id"/>
            </div>

            <div><{$lang.customer_code}>:</div>
            <div>
                <input id="customer_id" class="toEnter" type="text" value="" name="customer_id"/>
            </div>

            <div style="padding-left:10px"><{$lang.operation}><{$lang.type}>:</div>
            <div>
                <select id="cbh_op_type" class="mySelect" name="cbh_op_type">
                    <option value=''><{$lang.all}></option>
                    <{foreach key=key item=item from=$cbh_op_type}>
                    	<option value='<{$key+1}>'><{$item}></option>
                    <{/foreach}>                                       
                </select>
            </div>
            <div><{$lang.time}>:</div>
            <div>
                <{$lang.from}> <input type="text" class="dateFrom" id="dateFrom" style="width:65px;" name="dateFrom" class="input-width-1" />
                <{$lang.to}>:<input type="text" class="dateTo" id="dateTo" name="dateTo" style="width:65px;" class="input-width-1" /> 
            </div>

            <div class="tDiv8">
                <input id="searchSubmit" class="myButton" type="button" onclick="search();" value="<{$lang.search}>">
            </div>
            <!--<div class="tDiv1" permission="adduser">
                   <input class="myButton" type="button" value="<{$lang.add}>" onclick="editCustomer('')">
               </div>-->
            <div class="myClear"></div>

        </form>
    </div>
</div>

<div id="message" style="clear:both;color:red;"></div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="myTab">
    <thead>
    <tr>
    	<th><{$lang.No}></th>
        <th><{$lang.customer_code}></th>
        <th><{$lang.date}></th>
        <th><{$lang.payment}>/<{$lang.deposit}></th>
        <!--		<{$lang.payment}>;1:<{$lang.deposit}>-->
        <th><{$lang.money}></th>
        <th><{$lang.operation}><{$lang.type}></th>
        <th><{$lang.current}><{$lang.balance}></th>
        <th><{$lang.operation}></th>
        <th style="width:22%;"><{$lang.remark}><{$lang.detail}></th>
        <th style="width:10%;"><{$lang.referNo}></th>

    </tr>
    </thead>
    <tbody id="list">

    </tbody>
</table>

<div class="pagination"></div>

<style type="text/css">
    div#add {
        text-align: center;
    }

    div.info {
        text-align: left;
    }

    div.item {
        margin-bottom: 12px;
    }

    input.text {
        height: 22px;
        margin-left: 8px;
    }

    span.text {
        margin-left: 8px;
    }

    span.userInfoLeft {
        display: block;
        float: left;
        width: 100px;
    }
</style>

<div id="add" title="<{$lang.customer}><{$lang.msg}><{$lang.edit}>" style="display:none;">

    <div class="info">
        <div class="validateTips" id="tips"></div>

        <form id="createForm" name="createForm">

            <div class="item">
                <span class="userInfoLeft"><{$lang.customer}><{$lang.name}>:</span>
			<span class="userInfoRight">
				<input type="hidden" name="customer_id" id="customer_id"/>
				<input type="text" name="customer_name" id="customer_name"
                       class="text ui-widget-content ui-corner-all"/>
			</span>

                <div style="clear:both;"></div>
            </div>

            <div class="item">
                <span class="userInfoLeft"><{$lang.first_name}>:</span>
			<span class="userInfoRight">
				<input type="text" name="customer_first_name" id="customer_first_name"
                       class="text ui-widget-content ui-corner-all"/>
			</span>

                <div style="clear: both;"></div>
            </div>
            <div class="item">
                <span class="userInfoLeft"><{$lang.last_name}>:</span>
			<span class="userInfoRight">
				<input type="text" name="customer_last_name" id="customer_last_name"
                       class="text ui-widget-content ui-corner-all"/>
			</span>

                <div style="clear: both;"></div>
            </div>

            <div class="item">
                <span class="userInfoLeft"><{$lang.email}>:</span>
			<span class="userInfoRight">
				<input type="text" name="customer_email" id="customer_email"
                       class="text ui-widget-content ui-corner-all"/>
			</span>

                <div style="clear: both;"></div>
            </div>
            <div class="item">
                <span class="userInfoLeft"><{$lang.telphone}>:</span>
			<span class="userInfoRight">
				<input type="text" name="customer_telephone" id="customer_telephone"
                       class="text ui-widget-content ui-corner-all"/>
			</span>

                <div style="clear: both;"></div>
            </div>
            <div class="item">
                <span class="userInfoLeft"><{$lang.fax}>:</span>
			<span class="userInfoRight">
				<input type="text" name="customer_fax" id="customer_fax" class="text ui-widget-content ui-corner-all"/>
			</span>

                <div style="clear: both;"></div>
            </div>
            <div class="item">
                <span class="userInfoLeft"><{$lang.company}><{$lang.name}>:</span>
			<span class="userInfoRight">
				<input type="text" name="customer_company_name" id="customer_company_name"
                       class="text ui-widget-content ui-corner-all"/>
			</span>

                <div style="clear: both;"></div>
            </div>

            <div class="item">
                <span class="userInfoLeft"><{$lang.status}>:</span>
			<span class="text userInfoRight">
				<select name="customer_status" id="customer_status" class="ui-widget-content ui-corner-all">
                    <option value=''><{$lang.no}></option>
                    <option value='0'><{$lang.unactivate}></option>
                    <option value='1'><{$lang.activated}></option>
                    <option value='2'><{$lang.stop}></option>
                </select> *
			</span>

                <div style="clear: both;"></div>
            </div>
            <div class="item">
                <span class="userInfoLeft"><{$lang.default}><{$lang.language}>:</span>
			<span class="text userInfoRight">
				<select name="languages_id" id="languages_id" class="ui-widget-content ui-corner-all">
                    <option value='1'><{$lang.chinese}></option>
                    <option value='2'>English</option>
                </select> *
			</span>

                <div style="clear: both;"></div>
            </div>

        </form>

    </div>
</div>